#!/bin/bash

set -e
set -x

target=nginx01
pass=admin@2024

bypy download inotify-tools-3.14-1.oe2203sp4.x86_64.rpm

cp osync.sh /usr/bin/osync.sh
chmod +x /usr/bin/osync.sh

mkdir -p /opt/test1
sshpass -p$pass ssh -n $target mkdir -p /opt/test1

yum -y --disablerepo='*' localinstall inotify-tools-3.14-1.oe2203sp4.x86_64.rpm
cp osync.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl enable --now osync

set +x
set +e


# 项目地址
# https://gitcode.com/gh_mirrors/os/osync.git

# 简单模式
# osync.sh --initiator=/path/to/initiator/replica --target=ssh://[backupuser]@remotehost.com[:portnumber]//path/to/target/replica 
# osync.sh --initiator="/opt/test1" --target="ssh://root@nginx01:22//opt/test1"

# 监控模式
# yum install -y inotify-tools
# osync.sh --initiator="/opt/test1" --target="ssh://root@nginx01:22//opt/test1" --on-changes --no-resume